<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php make page list</title>

</head>
<body style="background: url('img/51137c50e5a88.jpg');">
<?php
$conn = mysqli_connect("localhost","root","","abcd");
if (!$conn){
    die("连接数据库失败：" . mysqli_error());
}
header("Content-type:text/html;charset=utf-8");
if(isset($_POST['button']))
{
    @session_start();
    $username=$_SESSION['username'];
    $a=$_POST['title'];
    $b=$_POST['content'];
    $sql="insert into gonggao(title,content,host) values('$a','$b','$username')";
    $c=mysqli_query($conn,$sql);
    if(!$c)
    {
        echo "<script language='javascript'>alert('公告失败');history.go(-1);</script>";
    }
    else {
        echo "<script language='javascript'>alert('公告成功');location.href='chakangonggao.php';</script>";
    }
}
?>

<table align="center" width="678">
    <tr>
        <td>
            <form name="form1" method="post" action="gonggao.php" onsubmit="return inputCheck(this)">
                <p>标题：</p>
                <p>
                    <input type="test" name="title" id="email" style="width: 300px;height: 30px;line-height: 30px">
                </p>
                <p>
                    内容：
                </p>
                <p>
                    <textarea name="content" cols="90" rows="20"></textarea>
                </p>
                <p>
                    <input type="submit" name="button" id="button" value="提交">
                    <input type="reset" value="重置">
                </p>
            </form>
        </td>
    </tr>
</table>
</body>
<script>
    function inputCheck(logoForm) {
        if(logoForm.title.value=="")
        {
            alert('标题不能为空');
            logoForm.title.focus();
            return false;
        }
        if(logoForm.content.value=="")
        {
            alert('内容不能为空');
            logoForm.content.focus();
            return false;
        }
    }
</script>
</html>
